﻿using mozhi.smarterp.Finance.Files;
using mozhi.smarterp.Finance.Ieps.Export;
using System;
using System.Threading.Tasks;

namespace mozhi.smarterp.Finance.Ieps
{
    public class ExportAppService : FinanceAppService, IExportAppService
    {
        private IServiceProvider _serviceProvider;

        public ExportAppService(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        public async Task<FileDto> ExportAsync(ExportQueryDto query)
        {
            var exportHandler = ExportHandlerFactory.Instance(query.ModuleCode, _serviceProvider);

            var file = await exportHandler.GetExportStreamAsync(query);

            return ObjectMapper.Map<File, FileDto>(file);
        }
    }
}
